<html>
<head><meta charset="utf-8"><title>SocketAddr/IpAddr in core · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html">SocketAddr/IpAddr in core</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240369033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240369033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240369033">(May 26 2021 at 18:28)</a>:</h4>
<p>Hey, an inconvenience that I’ve run into a couple of times when writing <code>#[no_std]</code> is that <code>std::net::SocketAddr</code>and its descendent types are unavailable.</p>
<p>This is quite annoying for building <code>#[no_std]</code> parsers and network libraries, which often times still have to handle socket addresses, but don’t have a shared type to use. The IETF RFCs these types are based on are used in a much broader set of targets than in is currently available in std, so I think that these types should move into core.</p>
<p>I understand why it’s not at the moment, which is that it often uses the underlying system <code>addr</code> representation, however I think there’s a very clear representation to use for all of the types in <code>#[no_std]</code>, which is <code>([u8; 4], u16)</code> for ipv4, and <code>([u16; 8], u16, u32, u32)</code> for ipv6.</p>
<p>What do other people think? How feasible would it be to create a core version of these types, without having a bunch of duplicated code between std and core, or exposing unnecessary internal details? I found a thread from over a year ago about this but didn’t see any libs people comment on it. <a href="https://internals.rust-lang.org/t/std-ipv4addr-in-core/11247">https://internals.rust-lang.org/t/std-ipv4addr-in-core/11247</a></p>



<a name="240369502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240369502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240369502">(May 26 2021 at 18:31)</a>:</h4>
<p>There is an effort to switch the representation of those types to a "raw" representation away from wrapping the libc types, but there is a long tail of external libraries that assume the libc layout via transmutes.</p>



<a name="240370053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240370053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240370053">(May 26 2021 at 18:34)</a>:</h4>
<p><span class="user-mention" data-user-id="243558">@Steven Fackler</span> That’s good to hear that there is an effort. I noticed there’s an explicit comment that the representation isn’t to be relied upon. Was that added after this became an issue?</p>



<a name="240370075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240370075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240370075">(May 26 2021 at 18:34)</a>:</h4>
<p>Yeah</p>



<a name="240370301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240370301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240370301">(May 26 2021 at 18:36)</a>:</h4>
<p>Is the list of libs using transmute being tracked somewhere?</p>



<a name="240371292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371292">(May 26 2021 at 18:43)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/78802">https://github.com/rust-lang/rust/pull/78802</a></p>



<a name="240371810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371810">(May 26 2021 at 18:47)</a>:</h4>
<p>This raises a general question that I think might be worth considering.</p>



<a name="240371852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371852">(May 26 2021 at 18:47)</a>:</h4>
<p>We currently try to make sure nothing in <code>core</code> is dependent on anything target-specific.</p>



<a name="240371912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371912">(May 26 2021 at 18:48)</a>:</h4>
<p><em>Should</em> we, though?</p>



<a name="240371939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371939">(May 26 2021 at 18:48)</a>:</h4>
<p>core, like std and alloc, still has to be built for the target.</p>



<a name="240371973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371973">(May 26 2021 at 18:48)</a>:</h4>
<p>wouldn't <code>asm!</code> be in core?</p>



<a name="240371988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240371988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240371988">(May 26 2021 at 18:48)</a>:</h4>
<p>There's no concept of sharing "the same" core between, say, <code>x86_64-unknown-linux-gnu</code> and <code>x86_64-unknown-linux-musl</code>.</p>



<a name="240372024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240372024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240372024">(May 26 2021 at 18:49)</a>:</h4>
<p>Let alone between two <code>x86_64</code> targets for different OSes entirely.</p>



<a name="240372119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240372119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240372119">(May 26 2021 at 18:49)</a>:</h4>
<p>Given that, I think it'd be perfectly reasonable for core to have <em>types</em> that vary based on target. That includes addr types, for instance.</p>



<a name="240373243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373243">(May 26 2021 at 18:57)</a>:</h4>
<blockquote>
<p>core, like std and alloc, still has to be built for the target.</p>
</blockquote>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Well one thing to keep in mind is custom targets which wouldn’t have a libc implementation to use. So there should still always be a representation for when there’s no appropriate target representation.</p>



<a name="240373565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373565">(May 26 2021 at 18:59)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> Sure. And in that case, we can have a default representation.</p>



<a name="240373795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373795">(May 26 2021 at 19:00)</a>:</h4>
<p>But, for instance, we could have <code>core::something::SocketAddr</code> that's re-exported as <code>std::net::SocketAddr</code>, and always matches the libc type iff there's a libc type.</p>



<a name="240373801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373801">(May 26 2021 at 19:00)</a>:</h4>
<p>For these types in particular, I think part of the desire was to make them smaller and less aligned by dropping some of the bits libc needs but we don't, in addition to no_std stuff</p>



<a name="240373855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373855">(May 26 2021 at 19:00)</a>:</h4>
<p><span class="user-mention" data-user-id="243558">@Steven Fackler</span> I get that. But I think if that were the <em>only</em> motivation, that wouldn't be worth breaking people's existing code, even if we consider that code questionable.</p>



<a name="240373908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373908">(May 26 2021 at 19:01)</a>:</h4>
<p>Yeah, agreed there</p>



<a name="240373986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240373986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240373986">(May 26 2021 at 19:01)</a>:</h4>
<p>And I think we don't <em>need</em> to break that compatibility just to move the type into core.</p>



<a name="240374012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240374012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240374012">(May 26 2021 at 19:01)</a>:</h4>
<p>I'd love to see quite a few types moved into core and re-exported from std.</p>



<a name="240374992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240374992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240374992">(May 26 2021 at 19:06)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Right, I was just pointing more in general that there will be other things in libc that don’t have reasonable target independent defaults.</p>



<a name="240376440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/SocketAddr/IpAddr%20in%20core/near/240376440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/SocketAddr.2FIpAddr.20in.20core.html#240376440">(May 26 2021 at 19:16)</a>:</h4>
<p>That seems likely. Are there types like that that we'd want to move into core though?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>